package com.metaera.app.ui.adapters;

import android.content.Context;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.metaera.app.R;
import com.metaera.app.data.model.ArticleListResponse;
import com.metaera.app.ui.activities.ArticleDetailsActivity;
import com.metaera.app.utils.DateUtils;

import java.util.List;

import androidx.annotation.NonNull;

public class ArticleRecommendAdapter extends BaseQuickAdapter<ArticleListResponse, BaseViewHolder> {

    public ArticleRecommendAdapter(List<ArticleListResponse> data) {
        super(R.layout.item_article_recommend, data);

        setOnItemClickListener((adapter, view, position) -> {
            Context context = view.getContext();
            context.startActivity(ArticleDetailsActivity.newInstance(context, getItem(position).getId()));
        });

    }

    @Override
    protected void convert(@NonNull BaseViewHolder holder, ArticleListResponse item) {
        holder.setText(R.id.tv_title, item.getTitle())
                .setText(R.id.tv_date, DateUtils.getTime(item.getRelease_time_stamp(), DateUtils.PATTERN_6)
                        + "\n" + DateUtils.getTime(item.getRelease_time_stamp(), DateUtils.PATTERN_4));

//        holder.getView(R.id.layout_container).setOnClickListener(v -> {
//            Context context = view.getContext();
//            context.startActivity(ArticleDetailsActivity.newInstance(context, getItem(position).getId()));
//        });
    }

}
